package com.whfp.coky.ui.task.vm.fluor

import android.content.Context
import androidx.core.view.isVisible
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import com.whfp.coky.R
import com.whfp.coky.databinding.FragFluorDetectionBinding
import com.whfp.coky.other.Constants
import com.whfp.coky.other.DialogBuilder
import com.whfp.coky.ui.base.BaseFragment
import com.whfp.coky.ui.base.BaseViewModel

/**
 *
 *
 * created by coky on 2022/3/1
 */
class FluorDetecFragVM: BaseViewModel<FragFluorDetectionBinding>() {

    var result = MutableLiveData<String>()
    var showInfoDetails = MutableLiveData(false)//显示信息详细

    var sexType = MutableLiveData<Int>(0)


    override fun observe(fragment: BaseFragment<*,*>, owner: LifecycleOwner) {
        super.observe(fragment, owner)
//        信息展开收起
        showInfoDetails.observe(fragment, Observer {
            vBinding.llIdentity.isVisible = it
            if (it){
                vBinding.sbInfos.setRightText("收起")
                vBinding.sbInfos.setRightDrawable(R.mipmap.icon_top_blue)
                (fragment as BaseFragment<*,*>).hideKeyboard(fragment.getActivity()?.currentFocus)
            }else{
                vBinding.sbInfos.setRightText("展开")
                vBinding.sbInfos.setRightDrawable(R.mipmap.icon_bottom_blue)
            }
        })
        sexType.observe(fragment, Observer {
            if (it in 0 until Constants.ARRAY_SEX.size){
                vBinding.tvSex.text = Constants.ARRAY_SEX[it].toString()
            }
        })
    }



    /**
     * 扫码身份证
     */
    fun doScanIdCard(){

    }
    /**
     * 扫码样本码
     */
    fun doScanSampleCode(){

    }
    /**
     * 开始测试
     */
    fun doFluorDetce(){

    }

    /**
     * 开始打印
     */
    fun doPrint(){

    }

    /**
     * 结果提交
     */
    fun doSubmit(){

    }

    fun showSexSelect(context: Context) {
        DialogBuilder.selectSingle(context,sexType.value!!,
            "性别:",
            Constants.ARRAY_SEX) {
            sexType.value = it.keys.first()
        }
    }
}